﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OutSourceLender.aspx.cs" Inherits="CRMWeb.Pages.Admin.OutSourceLender" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>OutSource Lender</title>
    <link rel="stylesheet" type="text/css" href="/Css/CrmStyle.css" />
     <link rel="stylesheet" type="text/css" href="/EasyUI/Themes/default/easyui.css" />
     <link rel="stylesheet" type="text/css" href="/EasyUI/Themes/icon.css" />
     <script type="text/javascript" src="/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/EasyUI/jquery.easyui.min.js"></script>
   
</head>
<body>
    <table id="dgOutsrclender" title="OutSource Lender" style="width: 600%; height: 370px"
          toolbar="#toolbarOutSourceLender" rownumbers="true" fitcolumns="true" singleselect="true">
        <thead>
            <tr>
                <th field="LenderID" width="100px">Lender ID</th>
                <th field="OutSourceLender" width="500px">OutSource Lender</th>
            </tr>
        </thead>
    </table>
    <div id="toolbarOutSourceLender">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newOutSourceLender()">New</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editOutSourceLender()">Edit</a>
        <a id="lnkDelete" href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#dlgDelOutsrcLender').dialog('open')" plain="true" iconcls="icon-remove" title="Delete Client">Delete</a>
    </div>
    <div id="dlgOutsrclender" class="easyui-dialog" style="width: 350px; height: 220px; padding: 10px 20px"
        closed="true" buttons="#dlg-buttons">
        <div class="ftitle">OutSource Lender Information</div>
        <form id="fmOutsrcLender" method="post" novalidate>
            <div class="fitem">
                <label style="width: 130px;">OutSource Lender:</label>
                <input id="txtOutSourceLender" style="width: 292px;" class="easyui-validatebox" required="true" />
                <input id="hdnLenderID" value="" style="display: none" />
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlgOutsrclender').dialog('close')" style="float: left">Cancel</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveOutSourceLender()">Save</a>
    </div>
     <div id="dlgDelOutsrcLender" class="easyui-dialog" title="Confirm" style="width: 300px; height: 160px" closed="true" resizable="false" modal="true">
        <h4 style="text-align: center">Are you sure want to delete this OutSource Lender?</h4>
        <div class="fitem" style="float: left; padding: 10px; margin-top: 10px">
            <a id="lnkDelLender" href="javascript:void(0)" class="easyui-linkbutton" onclick="deleteOutSourceLender()" disabled="true">OK</a>
            <a id="lnkCanclelender" href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#dlgDelOutsrcLender').dialog('close')" disabled="true">Cancel</a>
            <span id="spnanimate">
                <img id="deleteProgress" style="margin-left: 20px" src="../../Media/loading.gif" />
                <label id="lbltimeOuts" style="margin-left: 20px">5</label>
            </span>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#dlgDelOutsrcLender').dialog({
                onOpen: function () {
                    startCounter(5);

                },
                onClose: function () {
                    $('#lnkDelLender').linkbutton('disable');
                    $('#lnkCanclelender').linkbutton('disable');
                    $('#spnanimate').show();
                    $('#lbltimeOuts').html('');
                }
            });
        });


            function startCounter(limit) {
                setTimeout(function () {
                    if (limit == 0) {
                        $('#lnkDelLender').linkbutton('enable');
                        $('#lnkCanclelender').linkbutton('enable');
                        $('#spnanimate').hide();
                       
                    }
                    else {
                        $('#lbltimeOuts').html(limit);
                        startCounter(limit - 1);
                    }
                }, 1000);
            }


        var url;
        function newOutSourceLender() {
            $('#dlgOutsrclender').dialog('open').dialog('setTitle', 'New OutSource Lender');
            $('#fmOutsrcLender').form('clear');
            $('#txtOutSourceLender').val('');
            $('#hdnLenderID').val('');
            url = '/WebServices/OutSourceLender/OutSourceLenderAdd';
        }
        window.onresize = function () {
            $('#dgOutsrclender').datagrid('resize', {
                width: window.innerWidth,
                height: window.innerHeight
            });
        }
        function editOutSourceLender() {
            var row = $('#dgOutsrclender').datagrid('getSelected');
            if (row) {
                $('#dlgOutsrclender').dialog('open').dialog('setTitle', 'Edit OutSource Lender');
                $('#fmOutsrcLender').form('load', row);
                $('#txtOutSourceLender').val(row.OutSourceLender);
                $('#hdnLenderID').val(row.LenderID);
                url = '/WebServices/OutSourceLender/OutSourceLenderEdit?LenderID=' + row.LenderID;
            }
        }
        function deleteOutSourceLender() {
            var row = $('#dgOutsrclender').datagrid('getSelected');
            if (row) {
                $.ajax({
                    url: '/WebServices/OutSourceLender.ashx',
                    type: 'POST',
                    data: {
                        method: 'OutSourceLenderDelete',
                        args: { LenderID: row.LenderID }
                    },
                    success: function (data) {
                        $('#dgOutsrclender').datagrid('reload');
                        $('#dlgDelOutsrcLender').dialog('close');
                    }
                });
            }
        }
        function saveOutSourceLender() {
            var strOutSourceLender = $('#txtOutSourceLender').val();
            var LenderID = $('#hdnLenderID').val();

            if (LenderID != '') {
                if (strOutSourceLender != '') {
                    $.ajax({
                        url: '/WebServices/OutSourceLender.ashx',
                        type: 'POST',
                        data: {
                            method: 'OutSourceLenderEdit',
                            args: { LenderID: LenderID, OutSourceLender: strOutSourceLender }
                        },
                        success: function (data) {
                            if (data == 1) {
                                $('#dlgOutsrclender').dialog('close');
                                $('#dgOutsrclender').datagrid('reload');
                            }
                            else {
                                alert('OutSourceLender already exist');
                            }
                        }
                    });
                }
            }
            else {
                if (strOutSourceLender != '') {
                    $.ajax({
                        url: '/WebServices/OutSourceLender.ashx',
                        type: 'POST',
                        data: {
                            method: 'OutSourceLenderAdd',
                            args: { OutSourceLender: strOutSourceLender }
                        },
                        success: function (data) {
                            if (data == 1) {
                                $('#dlgOutsrclender').dialog('close');
                                $('#dgOutsrclender').datagrid('reload');
                            }
                            else {
                                alert('OutSourceLender already exist.');
                            }
                        }
                    });
                }
            }
        }

        $(document).ready(function () {
            $('#dgOutsrclender').datagrid({
                url:'/WebServices/OutSourceLender.ashx?method=OutSourceLenderSelect',
                onDblClickRow: function (index, rowdata) {
                    editOutSourceLender();
                }
            });
        });

    </script>
</body>
</html>
